﻿@model List<HZYProject.Domain.Chapter>
<style>
    .red {
        color: red
    }
</style>

<div class="layer-edit" style="padding:10px">
    <form id="formAdd" class="layui-form" action="" onsubmit="return false">
        <div class="layui-form-item">
            <label class="layui-form-label">所属章节<label class="red">*</label></label>
            <div class="layui-input-inline">
                <select id="ChapterID" name="ChapterID" lay-search="">
                    <option value="">--全部--</option>
                    @{
                        foreach (var item in Model)
                        {
                            <option value="@item.ChapterID">@item.Title</option>
                        }
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型<label class="red">*</label></label>
            <div class="layui-input-block">
                <input type="radio" name="typeName" value="1" title="单选题" checked="">
                <input type="radio" name="typeName" value="2" title="多选题">
                <input type="radio" name="typeName" value="3" title="填空题">
                <input type="radio" name="typeName" value="4" title="判断题">
                <input type="radio" name="typeName" value="5" title="拖拽题">
                <input type="radio" name="typeName" value="6" title="排序题">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">建议分值<label class="red">*</label></label>
            <div class="layui-input-block">
                <input type="radio" name="score" value="1" title="1分">
                <input type="radio" name="score" value="2" title="2分" checked="">
                <input type="radio" name="score" value="3" title="3分">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">题目<label class="red">*</label></label>
            <div class="layui-card-body">
                <textarea name="Title" id="edit" cols="30" rows="10"></textarea>
                @*<div class="layui-btn-group" style="margin-top: 10px">
                    <button class="layui-btn" lay-event="getContent">获取内容</button>
                </div>*@
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">解析</label>
            <div class="layui-input-block">
                <input id="knowledges" name="knowledges" maxlength="100" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary pear-btn-sm" onclick="addOption()">
                    <i class="layui-icon layui-icon-add-1"></i>
                    增加选项
                </button>
            </div>
        </div>
        <div id="OptionId">
            <div class="layui-form-item">
                <label class="layui-form-label">选项A<label class="red">*</label></label>
                <div class="layui-input-block">
                    <input type="text" id="optionA" name="optionA" class="layui-input" placeholder="请输入选项A的内容" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">答案<label class="red">*</label></label>
            <div class="layui-input-block">
                <input type="checkbox" name="answer" lay-skin="primary" title="A" value="A">
                <input type="checkbox" name="answer" lay-skin="primary" title="B" value="B">
                <input type="checkbox" name="answer" lay-skin="primary" title="C" value="C">
                <input type="checkbox" name="answer" lay-skin="primary" title="D" value="D">
            </div>
            <input type="hidden" id="answer" />
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary pear-btn-sm" lay-submit lay-filter="formDemo">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</div>
@section script{
    <script>
        layui.use(['form', 'jquery', 'tinymce'], function () {
            var form = layui.form;
            let $ = layui.jquery;
            let tinymce = layui.tinymce;

            var edit = tinymce.render({
                elem: "#edit",
                height: 400
            });

            //edit.getContent()

            form.on('submit(formDemo)', function (data) {
                var str = $("#formAdd").serialize();
                $.post("/Question/add", str, function (res) {
                    if (res.success) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }
                    else
                        layer.msg("添加失败：" + res.msg, {
                            icon: 2,
                            time: 1000
                        });
                }, "json");
                return false;
            });
        });

        function addOption() {
            var str = '<div class="layui-form - item"> ';
            for (var i = 0; i < 5; i++) {
                str += '<label class="layui-form-label">选项B<label class="red">*</label></label>';
                str += '<div class="layui-input-block">';
                str += '<input type="text" id="option'+i+'" name="optionB" class="layui-input" placeholder="请输入选项B的内容" autocomplete="off">';
                str += '</div>';
            }
            str += '</div>';
            document.getElementById("OptionId").innerHTML = str;
        }
    </script>
}